package com.sxc.OnlineStore.goods.dao;

import com.sxc.OnlineStore.Utils.ConnectMySql;
import com.sxc.OnlineStore.goods.domain.GoodsPay;

import java.sql.*;
import java.util.ArrayList;

public class GoodsPayIm {
    private Connection conn = ConnectMySql.conMysql();//定义好数据库对象
    private CallableStatement cs = null; //初始化调用存储过程
    private ResultSet rs = null; //定义rs
    private PreparedStatement ps = null;
    private String sql = null;


<<<<<<< HEAD
    public void GoodsPayInstant(String goods_details,String goods_price,String goods_number){
        try {
            GoodsPay goodsPay = new GoodsPay();

            cs = conn.prepareCall("call P_GoodsPayInstant(?,?,?)");
            //传值给存储过程
            cs.setString(1,goods_details);
            cs.setString(2,goods_price);
            cs.setString(3,goods_number);

            rs = cs.executeQuery();

            goodsPay.setGoods_details(goods_details);
            goodsPay.setGoods_price(goods_price);
            goodsPay.setGoodsPay_number(goods_number);

=======
    public void GoodsPayInstant( String user_id,String goods_id){
        try {
            GoodsPay goodsPay = new GoodsPay();

            cs = conn.prepareCall("call P_GoodsPayInstant(?,?)");
            //传值给存储过程
            cs.setString(1,user_id);
            cs.setString(2,goods_id);
            rs = cs.executeQuery();

>>>>>>> 还没有实现在servlet中获取sessiond
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

<<<<<<< HEAD

    public ArrayList<GoodsPay> QueryGoodsPay(){
        ArrayList<GoodsPay> goodsPayArrayList = new ArrayList<>();


        try {
            sql = "";
=======
    public ArrayList<GoodsPay> QueryGoodsPay(Object userPK,String goodsPK){
        ArrayList<GoodsPay> goodsPayArrayList = new ArrayList<>();
        try {
            sql = "SELECT\n" +
                    "\t g.goods_details,\n" +
                    "\t g.goods_price,\n" +
                    "\t gp.goodsPay_number \n" +
                    "FROM\n" +
                    "\t goods AS g,\n" +
                    "\t goodspay AS gp \n" +
                    "WHERE\n" +
                    "\t gp.goods_id = g.goods_id \n" +
                    "\tAND gp.user_id = "+userPK+" \n" +
                    "\tAND gp.goods_id = "+goodsPK+"";
>>>>>>> 还没有实现在servlet中获取sessiond
            ps = conn.prepareStatement(sql);

            rs = ps.executeQuery();

            while (rs.next()){
                GoodsPay goodsPay = new GoodsPay();

<<<<<<< HEAD
=======
                //获取当时使时间的值

                //给定每个字段的值
>>>>>>> 还没有实现在servlet中获取sessiond
                goodsPay.setGoods_details(rs.getString(1));
                goodsPay.setGoods_price(rs.getString(2));
                goodsPay.setGoodsPay_number(rs.getString(3));

                goodsPayArrayList.add(goodsPay);
                return  goodsPayArrayList;
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }

    public int GetGoodsPK (){

        return 0;
    }
}
